package com.bub.pay.framework.common.exception;

import com.bub.pay.framework.common.base.JsonAble;
import com.bub.pay.framework.common.base.Cause;
import com.bub.pay.framework.common.base.Module;

/**
 * 全局异常
 */
@SuppressWarnings("serial")
public class GlobalException extends RuntimeException implements JsonAble {

	public static final Integer CARRY = 0X3E8;

    public GlobalException(Module m, Cause factor, Throwable e) {
        super(factor.getInfo(),e);
        this.code = m.getSn() * CARRY + factor.getCode();
        this.info = factor.getInfo();
    }

    public GlobalException(Module m, Cause factor) {
        super(factor.getInfo());
        this.code = m.getSn() * CARRY + factor.getCode();
        this.info = factor.getInfo();
    }

    /**不能确定model,暂不使用*/
    public GlobalException(Cause cause){
        super(cause.getInfo());
        this.code = cause.getCode();
        this.info = cause.getInfo();
    }

    public GlobalException(Module m,Integer code,String info){
        super(info);
        this.code = m.getSn() * CARRY + code;
        this.info = info;
    }

    /**开放平台不返回5位数状态码*/
    public GlobalException(Integer code,String info){
        super(info);
        this.code = code;
        this.info = info;
    }


    private Integer code;
    private String info;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    @Override
    public String toString() {
        return toJsonStr();
    }

}
